package com.util;

import cn.hutool.core.date.ChineseDate;
import cn.hutool.core.date.DateUtil;
import com.constants.HolidayConstant;

import java.time.LocalDate;
import java.time.ZoneId;
import java.util.Date;

/**
 * @Author chl
 * @Description 获取当前年份法定节日的时间
 * @Date 16:27 2024/4/23
 * @return response response
 **/
public class HolidayUtil {

    /**
     * 获取假期时间
     * @param holidayName 假期名称
     * @param year 当前年份
     * @return
     */
    public static Date getHoliday(String holidayName, int year) {
        switch (holidayName) {
            case HolidayConstant.NEWYEARDAY:
                return DateUtil.parse(year + "-1-1");
            case HolidayConstant.CHINESENEWYEARGREGORIANFESTIVAL:
                ChineseDate chinesenewYearFestival = new ChineseDate(year, 1, 1);
                return chinesenewYearFestival.getGregorianDate();
            case HolidayConstant.QINGMINGFESTIVAL:
                int param = year - 2000;
                int qingmingDay = (int) (param * 0.2422 + 4.81) - param / 4;
                return DateUtil.parse(year + "-4-" + qingmingDay);
            case HolidayConstant.LABORDAY:
                return DateUtil.parse(year + "-5-1");
            case HolidayConstant.DRAGONBOATGREGORIANFESTIVAL:
                ChineseDate dragonBoatFestival = new ChineseDate(year, 5, 5);
                return dragonBoatFestival.getGregorianDate();
            case HolidayConstant.MIDAUTUMNGREGORIANFESTIVAL:
                ChineseDate midAutumnFestival = new ChineseDate(year, 8, 15);
                return midAutumnFestival.getGregorianDate();
            case HolidayConstant.NATIONALDAY:
                return DateUtil.parse(year + "-10-1");
            default:
                return new Date();
        }
    }

    public static void main(String[] args) {
        HolidayUtil holidayUtil=new HolidayUtil();
        //LocalDate.now().getYear()获取当前年份
        Date date = DateUtils.addYear(new Date(), 1);
        int year = DateUtils.getYear(date);
        Date qingmingFestival = holidayUtil.getHoliday(HolidayConstant.QINGMINGFESTIVAL, year);
        LocalDate localDate = qingmingFestival.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
        System.out.println(HolidayConstant.QINGMINGFESTIVAL +"时间为：" + localDate);

    }
}

